#ifndef PIPC_PROTOCOL_HPP
#define PIPC_PROTOCOL_HPP
#include <stdint.h>
#include <string>
#include <sys/time.h>

namespace pipc
{

typedef struct
{
    uint16_t cmd;
    uint16_t payloadLen;
    uint32_t tv_sec;
    uint32_t tv_usec;
} CmdHeader;

static const std::string PIPC_PROTOCOL_DELIMITER = "\t";

static const uint16_t HEADER_SUBSCRIBE_READER = 7;
static const uint16_t HEADER_SUBSCRIBE_WRITER = 8;
static const uint16_t HEADER_HANDSHAKE_COMMAND = 9;
static const uint16_t HEADER_SET_COMMAND = 10;
static const uint16_t HEADER_SET_NO_ACK_COMMAND = 11;
static const uint16_t HEADER_RECIEVED_COMMAND = 12;


inline int64_t timeval_to_usec( const struct timeval* tv )
{
    return( (int64_t)tv->tv_sec * 1000000 + tv->tv_usec ) ;
}

inline struct timeval* usec_to_timeval( int64_t usec, struct timeval* tv )
{
    tv->tv_sec = usec / 1000000 ;
    tv->tv_usec = usec % 1000000 ;
    return tv ;
}

}
#endif // PIPC_PROTOCOL_HPP
